import java.util.Arrays;

public class MyArrayList {
    public int[] elem;
    public int usedSize;
    public static final int EF = 10;

    public MyArrayList(){
        this.elem = new int[EF];
    }

    public void display(){
        for (int i = 0; i < usedSize; i++) {
            System.out.println(elem[i]);
        }
    }

    public void addFirst(int data){
        if(isFull()){
            enLarge();
        }
        for (int i = usedSize; i > 0; i++) {//记住使用头插法时要从后面开始删除，因为如果从前面开始删，会导致覆盖
            elem[i] = elem[i-1];
        }
        elem[0] = data;
        usedSize++;//忘记更新usedSize;
    }

    public void enLarge(){
        if(isFull()){
            this.elem = Arrays.copyOf(elem , 2*elem.length);
        }
    }

    public boolean isFull(){
        return elem.length == usedSize;
    }
}
